<?php
header('Access-Control-Allow-Origin:*'); 
/**
 * 取得roleId
 */
function GetRoleId(String $username,String $password)
{   
    $password = md5($password);
    $id = Mgetone(" select roleId from admin where username = '$username' and password = '$password' ");
    return $id;
}
/**
 * 取得roleName
 */
function GetRoleName(String $username,String $password)
{
    $roleId = GetRoleId($username,$password);
    $roleName = Mgetone("select roleName from role where id = '$roleId'");
    return $roleName;
}
/**
 * 登录方法
 */
function Login(String $username, String $password)
{
    $password = md5($password);
    $count = Mgetone("select count(*) from admin where username ='$username' and password = '$password'");
    if ($count != 0) return true;
    else return false;
}
/**
 * 取得所有admin方法
 */
function getAllAdmin(){
    $sql = "select admin.username,admin.id,admin.token,role.id as roleId,role.roleName from admin left join role on admin.roleId = role.id order by admin.id desc";
    return Mgetall($sql);
}
/**
 * 检查用户名是否存在
 */
function checkAdmin(String $username){
    $sql = "select count(*) from admin where username = '$username'";
    $count = Mgetone($sql);
    if ($count != 0){
        return true;
    }else{
        return false;
    }
}